home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 3.9 KB | 152 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWODFExc.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWODFEXC_H
- #define FWODFEXC_H
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWEXCLIB_H
- #include "FWExcLib.h"
- #endif
-
- #include <som.xh>
-
- //========================================================================================
- // Forward declarations
- //========================================================================================
-
- class FW_XException;
-
- //========================================================================================
- // Global functions
- //========================================================================================
-
- void FW_Failure(FW_PlatformError error);
- void FW_FailOnError(FW_PlatformError error);
- void FW_FailOnEvError(Environment* ev);
- void FW_SetEvError(Environment* ev, FW_PlatformError error);
- void FW_SetException(Environment *ev, const FW_XException& exception);
- FW_PlatformError FW_GetEvError(Environment* ev);
-
- //========================================================================================
- // CLASS FW_XException
- //========================================================================================
-
- class FW_XException
- {
- public:
- FW_DECLARE_EXCEPTION(FW_XException)
-
- virtual ~FW_XException();
- FW_XException(const FW_XException& exception);
- FW_XException(FW_PlatformError theError);
-
- FW_PlatformError GetPlatformError() const;
-
- private:
- const FW_PlatformError fPlatformError;
- };
-
- //========================================================================================
- // Macros
- //========================================================================================
-
- #ifdef SOMCHKEXCEPT
- #undef SOMCHKEXCEPT
- #endif
-
- #define SOMCHKEXCEPT ::FW_FailOnEvError(ev)
-
- // The following two macros are to be used in SOM methods that call C++ code that may throw.
- // Because we can't throw C++ exceptions from a SOM method (this would really toast things)
- // we have to make sure that any exception that may be thrown is caught and converted into
- // an error code and stored in the "ev" parameter.
- //
- // SOM_Scope long SOMLINK FW_OSomeClassSomeMethod(FW_OSomeClass *somSelf, Environment *ev)
- // {
- // ... usual SOM prologue ...
- // FW_SOM_TRY
- // {
- // A_Cxx_function_that_may_throw();
- // }
- // FW_SOM_CATCH
- // }
- //
-
- #define FW_SOM_TRY \
- FW_TRY
-
- #define FW_SOM_CATCH \
- FW_CATCH_BEGIN \
- FW_CATCH_REFERENCE(FW_XException, exception) \
- { \
- FW_SetException(ev, exception); \
- } \
- FW_CATCH_EVERYTHING() \
- { \
- FW_SetEvError(ev, FW_xUnknownError); \
- } \
- FW_CATCH_END
-
- // The following two macros are a variation on the above except exceptions are caught and
- // then gracefully dropped on the floor. This is for somUninit() method - if something
- // goes wrong in the destructor, there is not much that can be done. Besides, somUninit
- // does not have an "ev" pointer
-
- #define FW_SOM_UNINIT_TRY \
- FW_TRY
-
- #define FW_SOM_UNINIT_CATCH \
- FW_CATCH_BEGIN \
- FW_CATCH_EVERYTHING() \
- { \
- } \
- FW_CATCH_END
-
- // The following two macros are another variation on the above.
- // This time, we assume that a FW_PlatformError will be set intead of an Environment.
-
- #define FW_ERR_TRY \
- *error = FW_xNoError; \
- FW_TRY
-
- #define FW_ERR_CATCH \
- FW_CATCH_BEGIN \
- FW_CATCH_REFERENCE(FW_XException, exception) \
- { \
- *error = exception.GetPlatformError(); \
- } \
- FW_CATCH_EVERYTHING() \
- { \
- *error = FW_xUnknownError; \
- } \
- FW_CATCH_END
-
- #define FW_RETURN_ERR_TRY \
- FW_PlatformError error = FW_xNoError; \
- FW_TRY
-
- #define FW_RETURN_ERR_CATCH \
- FW_CATCH_BEGIN \
- FW_CATCH_REFERENCE(FW_XException, exception) \
- { \
- error = exception.GetPlatformError(); \
- } \
- FW_CATCH_EVERYTHING() \
- { \
- error = FW_xUnknownError; \
- } \
- FW_CATCH_END \
- return error;
-
- #endif
-